//
//  XMBaseTableViewController.swift
//  XMWeibo-Swift
//
//  Created by 育鑫 王 on 15/10/27.
//  Copyright © 2015年 育鑫 王. All rights reserved.
//

import UIKit

class XMBaseTableViewController: UITableViewController{

    let userLogin = XMUserAccount.userLogin()
    
    override func loadView() {
        
      userLogin ? super.loadView() : setUpVistorView()
    }
    
    private func setUpVistorView(){
        
        let vistorView = XMVistorView()
        
        view = vistorView
        
        //设置代理
        vistorView.vistorViewDelegate = self
        
        //背景颜色
        view.backgroundColor = UIColor(white: 237 / 255, alpha: 1)
        
        if self is XMHomeViewController{
            vistorView.startRotationAnimation()
        }else if self is XMMessageViewController{
            vistorView.setUpInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is XMDiscoverViewController{
            vistorView.setUpInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is XMProfileViewController{
            vistorView.setUpInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewRegistClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewLoginClick")
    }
    
}

extension XMBaseTableViewController : XMVistorViewDelegate{
   
    //MARK: - 代理方法
    func vistorViewLoginClick (){
        //加载授权界面
        let controller = XMOauthViewController()
        
        presentViewController(UINavigationController(rootViewController: controller), animated: true, completion: nil)
        
    }
    func vistorViewRegistClick() {
        print(__FUNCTION__)
    }
    
}
